package cn.zhang.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Slf4j
public class ChatClientController {

    private final ChatClient chatClient;

    public ChatClientController (ChatModel chatModel) {
        this.chatClient = ChatClient.builder(chatModel).build();
    }


    @GetMapping(value = "/chatClient/dochat")
    public String doChat(@RequestParam(name = "msg",defaultValue = "你是谁") String msg){
        return chatClient.prompt().user(msg).call().content();
    }

}
